app.controller('ActivityListController', [
  '$scope', 'Activity', 'activityList', '$location', function($scope, Activity, activityList, $location) {
    $scope.activityList = activityList;
    $scope.activityListClass = 'active';
    return $scope.detailView = function(activity) {
      return $location.path('/activity/detail/' + activity.id);
    };
  }
]);

app.controller('ActivityDetailController', [
  '$scope', 'Activity', 'activity', '$timeout', '$alert', '$location', function($scope, Activity, activity, $timeout, $alert, $location) {
    $scope.activityListClass = 'active';
    $scope.activity = activity;
    $scope.save = function() {
      return new Activity($scope.activity).$save({
        id: activity.id
      }, function() {
        return $alert({
          title: '保存成功',
          placement: 'top-right',
          type: 'info',
          show: true,
          duration: 2
        });
      });
    };
    return $scope["delete"] = function() {
      if (!confirm('确定删除此活动')) {
        return;
      }
      return new Activity($scope.activity).$delete({
        id: activity.id
      }, function() {
        var alert;
        alert = $alert({
          title: '删除成功',
          placement: 'top-right',
          type: 'info',
          show: true,
          duration: 2
        });
        return $timeout(function() {
          alert.hide();
          return $location.path('/activity/list');
        }, 2000);
      });
    };
  }
]);

app.controller('ActivityNewController', [
  '$scope', 'Activity', '$alert', '$timeout', '$location', function($scope, Activity, $alert, $timeout, $location) {
    $scope.activityNewClass = 'active';
    return $scope.save = function() {
      return new Activity($scope.activity).$save(function() {
        var alert;
        alert = $alert({
          title: '保存成功',
          content: '准备跳转到列表页',
          placement: 'top-right',
          type: 'info',
          show: true
        });
        return $timeout(function() {
          alert.hide();
          return $location.path('/activity/list');
        }, 2000);
      });
    };
  }
]);

app.controller('ActivitySignController', [
  '$scope', 'activitySignList', 'Activity', '$alert', '$timeout', '$location', function($scope, activitySignList, Activity, $alert, $timeout, $location) {
    $scope.activityListClass = 'activity';
    return $scope.activitySignList = activitySignList;
  }
]);

app.config([
  '$routeProvider', function($routeProvider) {
    $routeProvider.when('/activity/list', {
      templateUrl: '/admin/tmpl/activity_list',
      controller: 'ActivityListController',
      resolve: {
        activityList: function(Activity) {
          return Activity.query();
        }
      }
    });
    $routeProvider.when('/activity/new', {
      templateUrl: '/admin/tmpl/activity_new',
      controller: 'ActivityNewController'
    });
    $routeProvider.when('/activity/detail/:id', {
      templateUrl: '/admin/tmpl/activity_detail',
      controller: 'ActivityDetailController',
      resolve: {
        activity: function(Activity, $route) {
          return Activity.get({
            id: $route.current.params.id
          });
        }
      }
    });
    $routeProvider.when('/activity/:id/sign', {
      templateUrl: '/admin/tmpl/activity_sign',
      controller: 'ActivitySignController',
      resolve: {
        activitySignList: function(Activity, $route) {
          return Activity.getSignList($route.current.params.id);
        }
      }
    });
    return $routeProvider.when('/activity', {
      redirectTo: '/activity/list'
    });
  }
]);
